var prefix = ctx + "module/order"

$(function() {
	var columns = [{
            checkbox: true
        },
				{
			field : 'orderId', 
			title : '订单id' 
		},
				{
			field : 'orderNum', 
			title : '订单号' 
		},
				{
			field : 'order.typeName', 
			title : '订单类型' 
		},
				{
			field : 'customerClue.customerName', 
			title : '客户' 
		},
				{
			field : 'customerClue.customerCellphone', 
			title : '手机号码' 
		},
				{
			field : 'deptName', 
			title : '部门名称' 
		},
				{
			field : 'salesUserName', 
			title : '业务员' 
		},
				{
			field : 'serviceUserName', 
			title : '跟进客服' 
		},
				{
			field : 'visitTime', 
			title : '拜访时间' 
		},
				{
			field : 'visitStatus', 
			title : '是否回访',
			formatter : function(value, row, index) {
				if (value == 0) {
					return '<span class="label label-danger">未回访</span>';
				} else if (value == 1) {
					return '<span class="label label-primary">已回访</span>';
				}
			}
		},
				{
			field : 'vistitReturnTime', 
			title : '回访时间' 
		},
		        {
            title: '操作',
            align: 'center',
            formatter: function(value, row, index) {
            	var actions = [];
            	actions.push('<a class="btn btn-warning btn-sm ' + detailsFlag + '" href="#" title="详情" mce_href="#" onclick="details(\'' + row.orderId +'\' , \'' + row.recordId +'\')"><i class="fa fa-search"></i></a> ');				
				return actions.join('');
            }
        }];
	var url = prefix + "/visitRecordList";
	$.initTable(columns, url);
});


/*线上订单拜访记录-修改*/
function edit(recordId) {
    var url = prefix + '/form-orderVisitRecord/' + recordId;
    layer_showAuto("修改线上订单拜访记录", url);
}

/* 待跟进订单-详情*/
function details(orderId,recordId) {
    var url = prefix + '/detailsVisitRecord/' + orderId+"/"+recordId;
    layer_showAuto("回访列表详情 ", url);
}

// 单条删除
function remove(id) {
	$.modalConfirm("确定要删除选中线上订单拜访记录吗？", function() {
		_ajax(prefix + "/remove/" + id, "", "post");
    })
}

// 批量删除
function batchRemove() {
	var rows = $.getSelections("recordId");
	if (rows.length == 0) {
		$.modalMsg("请选择要删除的数据", "warning");
		return;
	}
	$.modalConfirm("确认要删除选中的" + rows.length + "条数据吗?", function() {
		_ajax(prefix + '/batchRemove', { "ids": rows }, "post");
	});
}
